package cn.unknownerror.ueteam.data;

import org.bukkit.configuration.Configuration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.java.JavaPlugin;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

public class ConfigurationManager {
    private Configuration config;
    private JavaPlugin plugin;
    private String configName;

    public ConfigurationManager(JavaPlugin plugin,String configName){
        this.plugin=plugin;
        this.configName=configName;
    }

    public void load(){
        File file=new File(plugin.getDataFolder(),configName);
        if(!file.exists()){
            plugin.saveResource(configName,true);
        }
        this.config= YamlConfiguration.loadConfiguration(file);
    }

    public void save(){
        this.plugin.saveConfig();
    }

    public Configuration getConfig() {
        return config;
    }

    public String getString(String path){
        String str=config.getString(path);
        return str==null?null:str.replace('&','§');
    }

    public List<String> getStringList(String path){
        List<String> list=new ArrayList<>();
        for (String str:config.getStringList(path)){
            list.add(str.replace('&','§'));
        }
        return list;
    }

}
